<?php
//-------------------------------------------------------------------------------------------------------
    require_once($config['app_dir'] . '/includes/db.class.php');
    //---------------------------------------------------------------------------------------------------
    class objPerformanceTable {

        public function build(){
          global $config;
          /*
			$show_days = 21;
            $min_show_days = 17;
            $period = 60*60*24 * $show_days;
            */
            $show_days = $config['show']['max_days'];//21;
            $min_show_days = $config['show']['min_days'];//17;
            $period = $config['show']['period'];//60*60*24 * $show_days;

            $now = getdate(mktime());
            $finish = mktime(0,0,0, $now['mon'], $now['mday'], $now['year']);
            $start = mktime(0,0,0,1,1,2006);
            $start_year = 2006;

            $result = ''; $data = array();
			for($y=$now['year']; $y>=$start_year; $y--)
			{

				$result.= $y.'<br>';
				$data[$y]['year']=$y;
				for($m=12; $m>=1; $m--)
				{
					if($y<$now['year'] || $m<$now['mon'])
					{
							if($finish >= $time + 60*60*24*$min_show_days)
							{
								$time = mktime(0,0,0,$m,16,$y);
								$now = getdate(mktime());
								$finish = mktime(0,0,0, $now['mon'], $now['mday'], $now['year']);
								if($time+$period < $finish)
									$finish = $time+$period;

								$data[$y]['periods'][]=array('month'=>$m, 'no'=>2, 'start' =>date('Y-m-d',$time), 'finish' => date('Y-m-d',$finish));
							}
							$time = mktime(0,0,0,$m,1,$y);
							$data[$y]['periods'][]=array('month'=>$m, 'no'=>1, 'start' =>date('Y-m-d',$time), 'finish' => date('Y-m-d',$time+$period));
					}

					else if($y==$now['year'] && $m==$now['mon'])
					{
						if($now['mday'] >= $min_show_days) //$show_days
						{
							$time = mktime(0,0,0,$m,1,$y);
							$now = getdate(mktime());
							$finish = mktime(0,0,0, $now['mon'], $now['mday'], $now['year']);
							if($time+$period < $finish)
								$finish = $time+$period;

							$data[$y]['periods'][]=array('month'=>$m, 'no'=>1, 'start' =>date('Y-m-d',$time), 'finish' => date('Y-m-d',$finish));
						}
					}
				}
			}

			return $data;
		}//build

        public function BuildPairs() {
		  global $Staff;
			$Pairs = new objPairsSystems();
			$Pairs->cache_time = 3*60;
			$Pairs->SystemID = $Staff->getSystem();
			return $Pairs->getAssocArr();
		/*
            $trades = objDataBase::GetInstance()->handler->CacheGetAll(3*60, $this->_sql_querys['trades']);//10 minute cache
            return $trades;
		*/
        } //BuildPairs
/*
        protected function _sqls() {
            //-------------------------------------------------------------------------------------------------------------------
            $this->_sql_querys['trades'] =
                'SELECT * FROM fa_trades t ORDER BY t.TradeID';

        } //_sqls
*/

    } //class PerformanceTable
//-------------------------------------------------------------------------------------------------------
?>
